package sale.wxb.loveshopping.config;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.annotation.JacksonStdImpl;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
@JacksonStdImpl
public class LocalDateSerializer extends JsonSerializer<LocalDateTime> {

    public static final LocalDateSerializer INSTANCE = new LocalDateSerializer();

    public LocalDateSerializer() {}

    @Override
    public void serialize(LocalDateTime localDateTime, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        String p =( (SimpleDateFormat) serializerProvider.getConfig().getDateFormat()).toPattern();
        String dts = localDateTime.format(DateTimeFormatter.ofPattern(p));
        jsonGenerator.writeString(dts);
    }
}
